home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GEN32.PAK / INIT.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  123 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   init.c
  9. //
  10. //  PURPOSE:   Performs application and instance specific initialization.
  11. //
  12. //  FUNCTIONS:
  13. //    InitApplication() - Initializes window data and registers window.
  14. //
  15. //  COMMENTS:
  16. //
  17.  
  18. #include <windows.h>            // required for all Windows applications
  19. #include "globals.h"            // prototypes specific to this application
  20. #include "resource.h"
  21.  
  22. HINSTANCE hInst;                // current instance
  23.  
  24. char szAppName[9];              // The name of this application
  25. char szTitle[40];               // The title bar text
  26.  
  27.  
  28. //
  29. //  FUNCTION: InitApplication(HINSTANCE, int)
  30. //
  31. //  PURPOSE: Initializes window data and registers window class.
  32. //
  33. //  PARAMETERS:
  34. //    hInstance - The handle to the instance of this application that
  35. //                is currently being executed.
  36. //    nCmdShow  - Specifies how the main window is to be displayed.
  37. //
  38. //  RETURN VALUE:
  39. //    TRUE  - Success
  40. //    FALSE - Initialization failed
  41. //
  42. //  COMMENTS:
  43. //
  44. //    This function is called at application initialization time.  It
  45. //    performs initialization tasks for the current application instance.
  46. //    Unlike Win16, in Win32, each instance of an application must register
  47. //    window classes.
  48. //
  49. //    In this function, we initialize a window class by filling out a data
  50. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  51. //    function.  Then we create the main window and show it.
  52. //
  53. //
  54.  
  55. BOOL InitApplication(HINSTANCE hInstance, int nCmdShow)
  56. {
  57.     WNDCLASSEX wc;
  58.     HWND       hwnd; // Main window handle.
  59.  
  60.     // Load the application name and description strings.
  61.  
  62.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  63.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  64.  
  65.     // Save the instance handle in static variable, which will be used in
  66.     // many subsequence calls from this application to Windows.
  67.  
  68.     hInst = hInstance; // Store instance handle in our global variable
  69.  
  70.     // Fill in window class structure with parameters that describe the
  71.     // main window.
  72.  
  73.     wc.cbSize        = sizeof(WNDCLASSEX);
  74.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  75.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  76.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  77.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  78.     wc.hInstance     = hInstance;               // Owner of this class
  79.     wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); // Icon name from .RC
  80.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  81.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  82.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  83.     wc.lpszClassName = szAppName;               // Name to register as
  84.     wc.hIconSm       = LoadImage(hInstance,        // Load small icon image
  85.                                  MAKEINTRESOURCE(IDI_APPICON),
  86.                                  IMAGE_ICON,
  87.                                  16, 16,
  88.                                  0);
  89.  
  90.     // Register the window class and return FALSE if unsuccesful.
  91.  
  92.     if (!RegisterClassEx(&wc))
  93.     {
  94.         //Assume we are running on NT where RegisterClassEx() is
  95.         //not implemented, so let's try calling RegisterClass().
  96.  
  97.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  98.             return FALSE;
  99.     }
  100.  
  101.     // Create a main window for this application instance.
  102.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call
  103.                         szTitle,             // Text for window title bar
  104.                         WS_OVERLAPPEDWINDOW, // Window style
  105.                         CW_USEDEFAULT, 0,    // Use default positioning
  106.                         CW_USEDEFAULT, 0,    // Use default size
  107.                         NULL,                // Overlapped has no parent
  108.                         NULL,                // Use the window class menu
  109.                         hInstance,           // This instance owns this window
  110.                         NULL                 // Don't need data in WM_CREATE
  111.     );
  112.  
  113.     // If window could not be created, return "failure"
  114.     if (!hwnd)
  115.         return FALSE;
  116.  
  117.     // Make the window visible; update its client area; and return "success"
  118.     ShowWindow(hwnd, nCmdShow);  // Show the window
  119.     UpdateWindow(hwnd);          // Sends WM_PAINT message
  120.  
  121.     return TRUE;                 // We succeeded...
  122. }
  123.